home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / tex / dvivga9.arc / PRTPAGE.H < prev    next >
Text File  |  1988-08-15  |  11KB  |  388 lines

  1. /* -*-C-*- prtpage.h */
  2. /*-->prtpage*/
  3. /**********************************************************************/
  4. /****************************** prtpage *******************************/
  5. /**********************************************************************/
  6.  
  7. void
  8. prtpage(bytepos)        /* print page whose BOP is at bytepos */
  9. long bytepos;
  10.  
  11. {
  12.     struct stack_entry
  13.     {
  14.     INT32 h;
  15.     COORDINATE hh;
  16.     INT32 v;
  17.     COORDINATE vv;
  18.     INT32 w, x, y, z;    /* what's on stack */
  19.     };
  20.     
  21.     register BYTE command;  /* current command                */
  22.     register INT16 i;        /* command parameter; loop index        */
  23.     unsigned char tc, ex;            /* temporary character            */
  24.     UNSIGN32 ht_rule;        /* rule height                              */
  25.     UNSIGN32 wd_rule;        /* rule width                               */
  26.     INT32 k,m;            /* temporary parameter            */
  27.     BOOLEAN seen_bop;        /* flag for noting processing of BOP    */
  28.     register INT16 sp;        /* stack pointer                */
  29.     struct stack_entry stack[STACKSIZE];    /* stack            */
  30.     char specstr[MAXSPECIAL+1];        /* \special{} string        */
  31.     INT32 w;            /* current horizontal spacing        */
  32.     INT32 x;            /* current horizontal spacing        */
  33.     INT32 y;            /* current vertical spacing            */
  34.     INT32 z;            /* current vertical spacing            */
  35.     unsigned int   keyhit, testcycle;
  36.  
  37. /***********************************************************************
  38. Process all commands  between the  BOP at bytepos  and the  next BOP  or
  39. POST.  The page is  printed when the  EOP is met,  but font changes  can
  40. also happen between EOP and BOP, so we have to keep going after EOP.
  41. ***********************************************************************/
  42.  
  43.     
  44.     seen_bop = FALSE;            /* this is first time through */
  45.     (void) FSEEK(dvifp,bytepos,0);    /* start at the desired position */
  46.  
  47.     for (testcycle = 0; 1 ; testcycle++)
  48.                         /*infinite" loop - exits when POST or second BOP met */
  49.     {
  50.     command = (BYTE)nosignex(dvifp,(BYTE)1);
  51.         
  52.  
  53. #if   ( BBNBITGRAPH | VGASCREEN)
  54.     /* If the test here on every byte proves to carry objectionable
  55.        overhead, it can be moved into the default, PUTx, and SETx
  56.        command sections. The goal is to give the user instant
  57.        response in page screen positioning, without having to wait
  58.        for the entire screen to be painted when it is just going
  59.        to be moved anyway.  This is the sort of display algorithm
  60.        that EMACS uses. */
  61. #if BBNBITGRAPH
  62.     if (kbinput() > 0)    /* user has typed something */
  63.         command = EOP;    /* so set for end-of-page action */
  64. #else
  65.         if(testcycle == 4) {
  66.             testcycle = 0; 
  67.             if( keyhit = _bios_keybrd(_KEYBRD_READY)) {
  68.             tc = (unsigned char)keyhit;
  69.             ex = keyhit >> 8;
  70.             
  71.             if(tc == 0 ) {      
  72.                  switch(ex) {
  73.                      case 72:           
  74.                          firstlinepage -= 96; 
  75.                      if(firstlinepage < MINM) firstlinepage = MINM;
  76.                          (void)getch();
  77.                          (void)getch();
  78.                          break;
  79.                      case 80:
  80.                          firstlinepage += 96; 
  81.                        if(firstlinepage > maxm) firstlinepage = maxm;
  82.                          (void)getch();
  83.                          (void)getch();
  84.                          break;
  85.                      case 71:
  86.                      case 79:
  87.                      case 75:
  88.                      case 77:
  89.                      case 81:
  90.                      case 73:
  91.                          command = EOP;
  92.                          brokenprtpage = 1;
  93.                          break;
  94.                      default:
  95.                          (void)getch();
  96.                          (void)getch();
  97.                  }
  98.              } else {
  99.                  switch(tc) {
  100.                      case 'q':
  101.                      case 'Q':
  102.                      case 'x':
  103.                      case 'X':
  104.                      case '\003':
  105.                      case '\031':
  106.                          (void)devterm();
  107.                          (void)dviterm();
  108.                          (void)alldone();    /* this never returns */
  109.                      case 'r':
  110.                      case 'R':
  111.                      case 'l':
  112.                      case 'L':
  113.                      case 'd':
  114.                      case 'D':
  115.                      case 'U':
  116.                      case 'u':
  117.                      case '\r':
  118.                      case '\n':
  119.                      case '0':
  120.                      case '1':
  121.                      case '2':
  122.                      case '3':
  123.                      case '4':
  124.                      case '5':
  125.                      case '6':
  126.                      case '7':
  127.                      case '8':
  128.                      case '9':
  129.                      case 'b':
  130.                      case 'B':
  131.                      case 's':
  132.                      case 'S':
  133.                          command = EOP;
  134.                          brokenprtpage = 1;
  135.                          break;
  136.                      default:
  137.                          (void)getch();
  138.                  }
  139.              }
  140.          }
  141.      }
  142. #endif
  143.         
  144. #endif
  145.  
  146.  
  147.     switch (command)
  148.     {
  149.  
  150.     case SET1:
  151.     case SET2:
  152.     case SET3:
  153.     case SET4:
  154.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-SET1+1)),TRUE);
  155.         break;
  156.  
  157.     case SET_RULE:
  158.         ht_rule = nosignex(dvifp,(BYTE)4);
  159.         wd_rule = nosignex(dvifp,(BYTE)4);
  160.         (void)setrule(ht_rule,wd_rule,TRUE);
  161.         break;
  162.  
  163.     case PUT1:
  164.     case PUT2:
  165.     case PUT3:
  166.     case PUT4:
  167.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-PUT1+1)),FALSE);
  168.         break;
  169.  
  170.     case PUT_RULE:
  171.         ht_rule = nosignex(dvifp,(BYTE)4);
  172.         wd_rule = nosignex(dvifp,(BYTE)4);
  173.         (void)setrule(ht_rule,wd_rule,FALSE);
  174.         break;
  175.  
  176.     case NOP:
  177.         break;
  178.  
  179.     case BOP:
  180.         if (seen_bop)
  181.         return;            /* we have been here already */
  182.         seen_bop = TRUE;
  183.  
  184.         for (i=0; i<=9; i++)
  185.         tex_counter[i] = (INT32)signex(dvifp,(BYTE)4);
  186.  
  187. #if    BBNBITGRAPH
  188.         (void)bopact();        /* display menu at top of page */
  189. #else /* not BBNBITGRAPH */
  190.  
  191. #if    (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
  192.         (void)bopact();
  193. #else /* NOT (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  194.         (void)clrbmap();
  195. #endif /* (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  196.  
  197.         if (!quiet)
  198.             (void)fprintf(stderr,"{%s}",tctos()); /* TeX page counters */
  199.         (void) nosignex(dvifp,(BYTE)4);    /* skip prev. page ptr */
  200. #endif /* BBNBITGRAPH */
  201.  
  202.         h = v = w = x = y = z = 0;
  203.         hh = lmargin;
  204.         vv = tmargin;
  205.         sp = 0;
  206.         fontptr = (struct font_entry*)NULL;
  207.         break;
  208.  
  209.     case EOP:
  210.  
  211. #if    (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
  212.         (void)eopact();
  213. #else
  214.         (void)prtbmap();
  215. #endif /* (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
  216.  
  217.         return;
  218.  
  219.     case PUSH:
  220.         if (sp >= STACKSIZE)
  221.         (void)fatal("prtpage():  stack overflow");
  222.         stack[sp].h = h;
  223.         stack[sp].hh = hh;
  224.         stack[sp].v = v;
  225.         stack[sp].vv = vv;
  226.         stack[sp].w = w;
  227.         stack[sp].x = x;
  228.         stack[sp].y = y;
  229.         stack[sp].z = z;
  230.         sp++;
  231.         break;
  232.  
  233.     case POP:
  234.         --sp;
  235.         if (sp < 0)
  236.         (void)fatal("prtpage():  stack underflow");
  237.         h = stack[sp].h;
  238.         hh = stack[sp].hh;
  239.         v = stack[sp].v;
  240.         vv = stack[sp].vv;
  241.         w = stack[sp].w;
  242.         x = stack[sp].x;
  243.         y = stack[sp].y;
  244.         z = stack[sp].z;
  245.         break;
  246.  
  247.     case RIGHT1:
  248.     case RIGHT2:
  249.     case RIGHT3:
  250.     case RIGHT4:
  251.         (void)moveover(signex(dvifp,(BYTE)(command-RIGHT1+1)));
  252.         break;
  253.  
  254.     case W0:
  255.         (void)moveover(w);
  256.         break;
  257.  
  258.     case W1:
  259.     case W2:
  260.     case W3:
  261.     case W4:
  262.         w = (INT32)signex(dvifp,(BYTE)(command-W1+1));
  263.         (void)moveover(w);
  264.         break;
  265.  
  266.     case X0:
  267.         (void)moveover(x);
  268.         break;
  269.  
  270.     case X1:
  271.     case X2:
  272.     case X3:
  273.     case X4:
  274.         x = (INT32)signex(dvifp,(BYTE)(command-X1+1));
  275.         (void)moveover(x);
  276.         break;
  277.  
  278.     case DOWN1:
  279.     case DOWN2:
  280.     case DOWN3:
  281.     case DOWN4:
  282.         (void)movedown(signex(dvifp,(BYTE)(command-DOWN1+1)));
  283.         break;
  284.  
  285.     case Y0:
  286.         (void)movedown(y);
  287.         break;
  288.  
  289.     case Y1:
  290.     case Y2:
  291.     case Y3:
  292.     case Y4:
  293.         y = signex(dvifp,(BYTE)(command-Y1+1));
  294.         (void)movedown(y);
  295.         break;
  296.  
  297.     case Z0:
  298.         (void)movedown(z);
  299.         break;
  300.  
  301.     case Z1:
  302.     case Z2:
  303.     case Z3:
  304.     case Z4:
  305.         z = signex(dvifp,(BYTE)(command-Z1+1));
  306.         (void)movedown(z);
  307.         break;
  308.  
  309.     case FNT1:
  310.     case FNT2:
  311.     case FNT3:
  312.     case FNT4:
  313.         (void)setfntnm((INT32)nosignex(dvifp,
  314.         (BYTE)(command-FNT1+1)));
  315.         break;
  316.  
  317.     case XXX1:
  318.     case XXX2:
  319.     case XXX3:
  320.     case XXX4:
  321.         k = (INT32)nosignex(dvifp,(BYTE)(command-XXX1+1));
  322.         if (k > MAXSPECIAL)
  323.         {
  324.         (void)sprintf(message,
  325.             "prtpage():  \\special{} string of %d characters longer \
  326. than DVI driver limit of %d -- truncated.",
  327.         k,MAXSPECIAL);
  328.         (void)warning(message);
  329.         }
  330.         m = 0;
  331.         while (k--)
  332.         {
  333.          tc = (unsigned char)nosignex(dvifp,(BYTE)1);
  334.          if (m < MAXSPECIAL)
  335.              specstr[m++] = tc;
  336.         }
  337.         specstr[m] = '\0';
  338.          (void) special(specstr);
  339.         break;
  340.  
  341.     case FNT_DEF1:
  342.     case FNT_DEF2:
  343.     case FNT_DEF3:
  344.     case FNT_DEF4:
  345.         if (preload)
  346.         (void)skipfont ((INT32) nosignex(dvifp,
  347.             (BYTE)(command-FNT_DEF1+1)));
  348.         else
  349.         (void)readfont ((INT32) nosignex(dvifp,
  350.             (BYTE)(command-FNT_DEF1+1)));
  351.         break;
  352.  
  353.     case PRE:
  354.         (void)fatal("prtpage():  PRE occurs within file");
  355.         break;
  356.  
  357.     case POST:
  358.         (void)devterm();        /* terminate device output */
  359.         (void)dviterm();        /* terminate DVI file processing */
  360.         (void)alldone();        /* this will never return */
  361.         break;
  362.  
  363.     case POST_POST:
  364.         (void)fatal("prtpage():  POST_POST with no preceding POST");
  365.         break;
  366.  
  367.     default:
  368.         if (command >= FONT_00 && command <= FONT_63)
  369.         (void)setfntnm((INT32)(command - FONT_00));
  370.         else if (command >= SETC_000 && command <= SETC_127)
  371.  
  372. #if    (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  373.         (void)setstr((BYTE)command); /* this sets several chars */
  374. #else
  375.         (void)setchar((BYTE)(command-SETC_000), TRUE);
  376. #endif /* (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2) */
  377.  
  378.         else
  379.         {
  380.         (void)sprintf(message,"prtpage():  %d is an undefined command",
  381.             command);
  382.         (void)fatal(message);
  383.         }
  384.         break;
  385.     }
  386.     }
  387. }
  388.